//
//  RCMessageCell.m
//  RocketProject
//
//  Created by chen jiedan on 13-11-14.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMessageCell.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "UIImageView+WebCache.h"


#define kBGImageFile            @"image_discount_cell_bg.png"


@implementation RCMessageCell{
    UIImageView *_imgView;
    
    UILabel *_nameLabel;
    UILabel *_contentLabel;
    UILabel *_dateLabel;
    UIImageView  *horizonLine;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        [self setBackgroundColorWithImage:bgImage];
        self.backgroundColor = [UIColor clearColor];
        
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



- (void) createPlaceHolder
{
    _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 80, 75)];
    [self.contentView addSubview:_imgView];
    [_imgView release];
    
    
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 15, 90, 15)];
    [self.contentView addSubview:_nameLabel];
    _nameLabel.font = [UIFont fontWithName:kFontNameHeiti size:14];
    _nameLabel.textColor = kNormalOrangeTextColor;
    [_nameLabel setBackgroundColor:[UIColor clearColor]];
    [_nameLabel release];
    
    _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 15, 100, 15)];
    [self.contentView addSubview:_dateLabel];
    _dateLabel.textAlignment = NSTextAlignmentRight;
    _dateLabel.font = [UIFont fontWithName:kFontNameHeiti size:12];
    _dateLabel.textColor = kNormalTextColor;
    [_dateLabel setBackgroundColor:[UIColor clearColor]];
    [_dateLabel release];
    
    _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 35, 190, 60)];
    [self.contentView addSubview:_contentLabel];
    _contentLabel.font = [UIFont fontWithName:kFontNameHeiti size:12];
    _contentLabel.textColor = kNormalTextColor;
    _contentLabel.numberOfLines = 0;
    [_contentLabel setBackgroundColor:[UIColor clearColor]];
    [_contentLabel release];

    
    horizonLine = [[UIImageView alloc]initWithFrame:CGRectMake(0, 99, 320, 1)];
    horizonLine.backgroundColor = [UIColor clearColor];
    [horizonLine setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image_line_type3.png" ofType:nil]]];
    [self.contentView addSubview:horizonLine];
    [horizonLine release];
    
}

- (void) bindData:(RCMessageListItemDataModel *)item
{
    [_imgView setImageWithURL:[NSURL URLWithString:item.avatar] placeholderImage:[UIImage imageNamed:@"bg_noticeAvatar"]];
    _nameLabel.text = item.username;
    _contentLabel.text = item.content;
    _dateLabel.text = item.datetime;
    
}


+ (CGFloat) cellHeight:(RCMessageListItemDataModel *)item
{
    return 100;
}

@end
